package com.crm.customer.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.crm.customer.model.Customer;
import com.service.CustomerService;

public class CustomerAddController extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2718769641940917173L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.getRequestDispatcher("/View/CustomerAdd.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		CustomerService model = new CustomerService();

		Customer customer = new Customer(req.getParameter("customer_id"),
				req.getParameter("firstName"), req.getParameter("lastName"),req.getParameter("sex"),req.getParameter("package_id"),
				req.getParameter("employee_id"),Integer.parseInt(req.getParameter("age")),Integer.parseInt(req.getParameter("height")),Integer.parseInt(req.getParameter("weight")));

		boolean result = model.addCustomer(customer);
		if (result){
			req.getRequestDispatcher("/View/CustomerAddSuccess.jsp").forward(req, resp);
		}else{
			req.getRequestDispatcher("/View/CustomerAddFailed.jsp").forward(req, resp);
		}
	}
}

